﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Itfort.Web;
using WanPiJie.Products;

namespace WanPiJie.WebSite.Products
{
	public partial class Detail : PageBase
	{
		/// <summary>
		/// 商品的唯一编号
		/// </summary>
		public long SerialNumber
		{
			get;
			private set;
		}

		/// <summary>
		/// 商品销售信息扩展
		/// </summary>
		public Commodity SalesInfoExtension
		{
			get;
			private set;
		}

		/// <summary>
		/// 相关联产品的列表
		/// </summary>
		public IList<Commodity> RelatedSalesInfoExtensions
		{
			get;
			private set;
		}

		/// <summary>
		/// Get请求出来
		/// </summary>
		protected override void HttpGetProcess()
		{
			base.HttpGetProcess();
			this.SerialNumber = this.Request.ToInt64("ItemId");
			if (this.SerialNumber != 0)
			{
				this.SalesInfoExtension = WpjSf.CommodityService.GetCommodity(this.SerialNumber);
			}
			if (this.SerialNumber != 0 && this.SalesInfoExtension != null)
			{
				this.GetRelatedSalesInfo();
			}
			else
			{
				this.Response.Redirect("../Default.aspx");
			}

			this.rptProductList.DataSource = RelatedSalesInfoExtensions;
			this.DataBind();
		}

		/// <summary>
		/// 获取关联商品列表
		/// </summary>
		protected void GetRelatedSalesInfo()
		{
			this.RelatedSalesInfoExtensions = WpjSf.CommodityService.GetRelatedCommodities(this.SalesInfoExtension, 1, 4);
		}

		/// <summary>
		/// 卖家信用等级处理
		/// </summary>
		/// <param name="score">卖家等级分数</param>
		/// <returns>等级图片路径</returns>
		public string GetCreditImage()
		{
			string url = "http://static.wanpijie.com/images/{0}.gif";
			if (this.SalesInfoExtension.SellerCreditScore > 15)
			{
				return string.Format(url, string.Format("s_crown_{0}", this.SalesInfoExtension.SellerCreditScore % 15));
			}
			else
			{
				return string.Format(url, string.Format("s_cap_{0}", this.SalesInfoExtension.SellerCreditScore % 10));
			}
		}

		/// <summary>
		/// 获取类目对象信息
		/// </summary>
		/// <param name="catalogId">类目Id</param>
		/// <returns>类目对象</returns>
		protected Catalog GetCatalog(long catalogId)
		{
			return WpjSf.CategoryService.GetCatalogById(catalogId);
		}
	}
}